import Vue from "vue";
import vuex from "vuex";

Vue.use(vuex);

export default new vuex.Store({
  state: {
    collapse: false,
    tags: []
  },
  mutations: {
    toggleCollapse(state) {
      state.collapse = !state.collapse;
    },
    updateTags(state, Object) {
      let index = -1;
      state.tags.forEach((item, i) => {
        item.active = false;
        if (item.path === Object.path) {
          index = i;
        }
      });
      if (index > -1) {
        state.tags[index].active = true;
      } else {
        Object.active = true;
        state.tags.push(Object);
      }
    }
  },
  actions: {}
});
